#!/bin/sh

set -e

python /usr/local/bin/change_db.py

cmd="redis-load -u ${JIANMU_HOST}:${JIANMU_PORT}"

if [[ -n ${JIANMU_PASSWORD} ]]; then
  cmd="${cmd} -a ${JIANMU_PASSWORD}"
fi

if [[ -n ${JIANMU_DATABASE} ]]; then
    cmd="${cmd} -d ${JIANMU_DATABASE}"
fi

cat /tmp/redis_import.json

`cat /tmp/redis_import.json | $cmd 2> /tmp/error`

if [[ -s /tmp/error ]]; then
  cat /tmp/error
  exit 1
fi

echo "Import data success"

